//
//  DemoDicLoop.swift
//  swiftDemo
//
//  Created by JIENING ZHANG on 2020/1/8.
//  Copyright © 2020 lovivid. All rights reserved.
//

import UIKit

class DemoDicLoop: NSObject {
    class func demoLogic() {
        let monthDic : [String : Int] = [
            "January" :     31,
            "February" :    28,
            "March" :       31,
            "April" :       30,
            "May" :         31,
            "June" :        30,
            "July" :        31,
            "August" :      31,
            "September" :   30,
            "October" :     31,
            "November" :    30,
            "December" :    31,
        ];
        
        var longMonthDic : [String : Int] = [:];
        var shortMonthDic : [String : Int] = [:];
        
        for (key, value) in monthDic {
            if value > 30 {
                longMonthDic[key] = value;
            } else {
                shortMonthDic[key] = value;
            }
        }
        
        print("longMonthDic=\(longMonthDic)")
        print("shortMonthDic=\(shortMonthDic)")
        
        longMonthDic.keys.forEach { (key) in
            print("longMonthDic, key=\(key), value=\(longMonthDic[key] ?? 0)")
        }
/*
输出:
         
longMonthDic=["January": 31, "August": 31, "December": 31, "March": 31, "May": 31, "October": 31, "July": 31]
shortMonthDic=["February": 28, "November": 30, "September": 30, "June": 30, "April": 30]
longMonthDic, key=January, value=31
longMonthDic, key=August, value=31
longMonthDic, key=December, value=31
longMonthDic, key=March, value=31
longMonthDic, key=May, value=31
longMonthDic, key=October, value=31
longMonthDic, key=July, value=31
*/
    }
}
